package com.activemq.boot;

import lombok.extern.slf4j.Slf4j;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.jms.Topic;
import java.util.UUID;

@Slf4j
@Service
public class MsgProducer {
    @Resource
    private Topic topic;

    @Resource
    JmsMessagingTemplate jmsMessagingTemplate;

    public void sendMessage() {
        jmsMessagingTemplate.convertAndSend(topic, "测试" + UUID.randomUUID().toString().substring(0, 8));
    }

    @Scheduled(fixedDelay = 3000)
    public void scheduleSend() {
        sendMessage();
    }
}
